<?php
class GoodsViewModel extends ViewModel{
	protected $tableName='goods';
	protected $viewFields=array(
		'goods'=>array(
			'id','name','sprice','unit','inventory','click','time','number',
			'_type'=>'LEFT'
			),
		'intro'=>array(
			'max','medium','mini','intro','service',
			'_on'=>'goods.id=intro.gid',
			'_type'=>'LEFT'
			),
		'brand'=>array(
			'id'=>'bid','name'=>'bname',
			'logo',
			'_on'=>'goods.bid=brand.id'
			)
			);
	public function getAll($id){
		$where=array('id'=>$id);
		$result=$this->where($where)->find();
		$result['max']=explode('|',$result['max']);
		$result['medium']=explode('|',$result['medium']);
		$result['mini']=explode('|',$result['mini']);
		$db=D('GoodsAttrView');
		$attr=$db->where(array('gid'=>$id))->order('id')->select();
		$result['attr']=array();
		$result['spec']=array();
		foreach($attr as $v){
			if($v['type']){
				$result['spec'][$v['name']][]=array(
					'id'=>$v['id'],
					'value'=>$v['value']
					);
			}else{
				$result['attr'][]=array(
					'name'=>$v['name'],
					'value'=>$v['value']
					);
			}
		}
		//p($result);
		return $result;
	}
}
?>